<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>编辑菜单</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="__ADMIN_STATIC__/css/oksub.css">
  <script type="text/javascript" src="__STATIC__/lib/loading/okLoading.js"></script>
</head>
<body>
<div class="ok-body">
  <blockquote class="layui-elem-quote">
    <p>编辑菜单</p>
  </blockquote>
  <blockquote class="layui-elem-quote layui-quote-nm">
    <form class="layui-form" action="">
      <div class="layui-form-item">
        <label class="layui-form-label">菜单名称</label>
        <div class="layui-input-block">
          <input type="text" name="name" required  lay-verify="required" value="{$model.name}" placeholder="菜单名称" autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">菜单路由</label>
        <div class="layui-input-block">
          <input type="text" name="route" value="{$model.route}" placeholder="菜单路由" autocomplete="off" class="layui-input">
          <div class="layui-form-mid layui-word-aux">请填写正确的路由地址(如: index/index)</div>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">菜单图标</label>
        <div class="layui-input-block">
          <input type="text" name="icon" value="{$model.icon}" placeholder="菜单图标" autocomplete="off" class="layui-input">
          <div class="layui-form-mid layui-word-aux">Layui官网选择图标编码即可</div>
        </div>

      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
          <input type="text" name="sort" value="{$model.sort}"  placeholder="排序" autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">父菜单</label>
        <div class="layui-input-block">
          <select name="parent_id" lay-verify="required">
            <option value="0">顶级菜单</option>
            {foreach $parents as $k => $parent}
            <option {if $model.parent_id == $k}selected="selected"{/if} value="{$k}">{$parent}</option>
            {/foreach}
          </select>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-block">
          <select name="type">
            <option value=""></option>
            <option {if $model.type == 1}selected="selected"{/if} value="1">前端</option>
            <option {if $model.type == 2}selected="selected"{/if} value="2">后端</option>
          </select>
        </div>
      </div>

      <div class="layui-form-item">
        <div class="layui-input-block">
          <button class="layui-btn" lay-submit lay-filter="formMenu">立即提交</button>
          <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
      </div>
    </form>

  </blockquote>

</div>
<!--js逻辑-->
<script src="__STATIC__/lib/layui/layui.js"></script>
<script>
    layui.use(["okLayer",'form','jquery','okUtils'], function () {
        let form = layui.form,
            okUtils = layui.okUtils,
            okLayer = layui.okLayer,
            $ = layui.jquery;
        okLoading.close();

        //监听提交
        form.on("submit(formMenu)", function (data) {
            okUtils.ajax("{:url('menu/update',['id'=>$model.id])}", "post", data.field, true).done(function (response) {
                okLayer.greenTickMsg(response.msg, function () {
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                });
            }).fail(function (error) {
                console.log(error)
            });
            return false;
        });
    });
</script>
</body>
</html>
